package com.zztl.infiniteBand.presenter

import android.content.Context
import com.zztl.infiniteBand.base.BasePresenter
import com.zztl.infiniteBand.model.ContactInfoBean
import com.zztl.infiniteBand.model.FirmwareVersionBean
import com.zztl.infiniteBand.model.VersionResponseBean
import com.zztl.infiniteBand.net.FilterSubscriber2
import com.zztl.infiniteBand.net.RetorfitServiceManger
import com.zztl.infiniteBand.net.converter.DataConverter
import com.zztl.infiniteBand.net.requestBean.FirmwareVersionRequest
import com.zztl.infiniteBand.net.requestBean.GetVersionRequest
import com.zztl.infiniteBand.ui.view.mvpview.ContactInfoView

/**
 * @desc
 * @auth ${user}
 * @time 2018/9/21  15:54
 */
class SyncStepPresenter : BasePresenter<ContactInfoView>() {
   /* fun syncStep(request: SyncStepRequest, context: Context) {
        addSubscribe(RetorfitServiceManger
                .observe(RetorfitServiceManger.instance!!.apiService.syncStep(DataConverter.instance.toJson(request)))
                .subscribe(object : FilterSubscriber2<NoDataResponseBean>(context) {
                    override fun success(bean: NoDataResponseBean) {
                        view!!.syncStepFail(false)
                    }

                    override fun fail(msg: String?) {
                        view!!.syncStepFail(true)
                    }


                }))
    }*/

    fun getContactInfo(context: Context) {
        addSubscribe(RetorfitServiceManger
                .observe(RetorfitServiceManger.instance!!.apiService.getContactInfo(""))
                .subscribe(object : FilterSubscriber2<ContactInfoBean>(context) {
                    override fun success(bean: ContactInfoBean) {

                        view!!.getSuccess(bean)
                    }

                    override fun fail(message: String?) {

                    }
                }))
    }

    fun getVersion(context: Context) {
        addSubscribe(RetorfitServiceManger
                .observe(RetorfitServiceManger.instance!!.apiService.getVersion(DataConverter.instance.toJson(GetVersionRequest("Android"))))
                .subscribe(object : FilterSubscriber2<VersionResponseBean>(context) {
                    override fun success(bean: VersionResponseBean) {

                       view!!.update(bean)
                    }

                    override fun fail(message: String?) {

                    }
                }))
    }


    fun getFirmwareVersion(request: FirmwareVersionRequest, context: Context) {
        addSubscribe(RetorfitServiceManger
                .observe(RetorfitServiceManger.instance!!.apiService.getFirmwareVersion(DataConverter.instance.toJson(request)))
                .subscribe(object : FilterSubscriber2<FirmwareVersionBean>(context) {
                    override fun success(bean: FirmwareVersionBean) {
                        view!!.getVersion(bean)
                    }

                    override fun fail(message: String?) {

                    }


                }))
    }


}
